# !/usr/bin/env python
# encoding: utf-8
'''
  @author: HJW
  @license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
  @contact: hejunwang01@126.com
  @file: selenium_spider.py
  @time: 2022/8/27 0027 下午 16:27
  @desc:
  '''


from selenium import webdriver
import time

from lxml import etree

from selenium.webdriver.common.by import By
# 五可视化界面
from selenium.webdriver.chrome.options import Options

#导入实现规避检测包
from selenium.webdriver import ChromeOptions


# 进入浏览器设置
# options = webdriver.ChromeOptions()
# # 谷歌无头模式
# options.add_argument('--headless')
# options.add_argument('--disable-gpu')
# # 设置页面大小
# options.add_argument('window-size=1200x600')
# # 设置中文
# options.add_argument('lang=zh_CN.UTF-8')
# # 更换头部
# options.add_argument(
#     'user-agent="Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"')
# # 设置代理
# options.add_argument('proxy-server=' + proxy)
# # 不加载图片
# prefs = {"profile.managed_default_content_settings.images": 2}
# options.add_experimental_option("prefs", prefs)
# # 导入当前py文件目录下的chromedriver
# executable_path = os.path.abspath('chromedriver.exe')




#
# list_a = tree.xpath('//div[@class="acc-inf"]/div')
# print(list_a)
# for a in list_a:
#     text = a.xpath('./a[2]/text()')[0]
#     print(text)

# driver.find_element(by=By.XPATH,value='//div[2][@class="acc-inf"]/div[4]/a[2]').click()
#
# time.sleep(2)
# driver.find_element(by=By.XPATH,value='//div[2][@class="acc-inf"]/div[4]/a[1]').click()

# driver.find_element(By.PARTIAL_LINK_TEXT,u"充值积分").click()



def login():
    #     options 添加
    chrome_options = Options()
    # # 谷歌无头模式
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument("--window-size=1920,1050")  # 专门应对无头浏览器中不能最大化屏幕的方案,把尺寸放大点
    # 驱动地址
    executable_path = r'./chrome驱动/chromedriver.exe'
    #实现规避检测
    option =ChromeOptions()
    option.add_experimental_option('excludeSwitches',['enable-automation'])


    driver = webdriver.Chrome(executable_path=executable_path,
                              chrome_options=chrome_options,
                              options=option)

    url = "https://zhuce.jfbym.com/login/"
    # 五可视化界面
    driver.get(url)
    # driver.maximize_window()

    # 如果定位的标签在iframe中, 需要进行切换  ""
    # driver.switch_to.frame('xxxxx')

    # 模拟登录
    driver.find_element(by=By.NAME, value="phone").send_keys("13726412604")
    time.sleep(2)

    driver.find_element(by=By.NAME, value="password").send_keys("123456")
    time.sleep(2)

    driver.find_element(by=By.ID, value="loginBtn").click()
    time.sleep(12)


    driver.find_element(By.PARTIAL_LINK_TEXT, u"签到得积分").click()

    time.sleep(2)

    # driver.find_element(By.PARTIAL_LINK_TEXT, u"充值积分").click()
    #
    # time.sleep(2)
    driver.save_screenshot('./img/yundama.png')

    driver.quit()

if __name__ == '__main__':
    login()



